<template>
  <div class="app-container">
    <el-row :gutter="20">
      <!--用户数据-->
      <el-col :span="24" :xs="24">
        <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch"
                 label-width="68px">

          <el-form-item label="时间">
            <el-date-picker
              v-model="dateRange"
              style="width: 240px"
              value-format="yyyy-MM-dd"
              type="daterange"
              range-separator="-"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
            ></el-date-picker>
          </el-form-item>

          <el-form-item label="" prop="userId">
            <el-select
              v-model="queryParams.userId"
              placeholder="请选择"
              clearable
              style="width: 240px"
            >
              <el-option
                v-for="item in userList"
                :key="item.userId"
                :label="item.userName"
                :value="item.userId"
              />
            </el-select>
          </el-form-item>

          <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-form>

        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button
              type="warning"
              plain
              icon="el-icon-download"
              size="mini"
              @click="handleExport"
            >{{ $t("export") }}
            </el-button>
          </el-col>
        </el-row>

        <el-table border v-loading="loading" :data="indexList" style="margin-top: 20px;">
          <el-table-column type="index" width="50"/>
          <el-table-column label="日期" align="center" prop="buildDate"/>
          <el-table-column label="商户码" align="center" prop="companyName"/>
          <el-table-column label="催收人" align="center" prop="userName"/>
          <el-table-column label="总单数" align="center" prop="totalNum" width="100">
            <template slot-scope="scope">
              {{scope.row.totalNum + scope.row.addNum}}
            </template>
          </el-table-column>
          <el-table-column label="当天到期单数" align="center" prop="expireDay"/>
          <el-table-column label="当天还款单数" align="center" prop="expirePayDay"/>
          <el-table-column label="当天到期催回率" align="center" prop="expirePayDay">
            <template slot-scope="scope">
              <span v-if="scope.row.expirePayDay==0 || scope.row.expireDay == 0">0.00%</span>
              <span v-else> {{ scope.row.expirePayDay / scope.row.expireDay | numFilter }}%</span>
            </template>
          </el-table-column>
          <el-table-column label="当天本金催回率" align="center" prop="repayMoney">
            <template slot-scope="scope">
              <span v-if="scope.row.expireMoneyDay==0 || scope.row.dayMoney == 0">0.00%</span>
              <span v-else> {{ scope.row.expireMoneyDay / scope.row.dayMoney | numFilter }}%</span>
            </template>
          </el-table-column>
          <el-table-column label="-1天本金催回率" align="center" prop="beforeDayMoney">
            <template slot-scope="scope">
              <span v-if="scope.row.beforeDayMoney == 0 || scope.row.beforeDayRepayMoney == 0">0.00%</span>
              <span v-else>{{ scope.row.beforeDayMoney / scope.row.beforeDayRepayMoney | numFilter }}%</span>
            </template>
          </el-table-column>
          <el-table-column label="-1天到期单数" align="center" prop="beforeDayNum"/>
          <el-table-column label="当日触达订单数" align="center" prop="dayRemarkNum"/>
          <el-table-column label="更新时间" align="center" prop="createTime" width="160">
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.createTime) }}</span>
            </template>
          </el-table-column>
        </el-table>

        <pagination
          v-show="total>0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />
      </el-col>
    </el-row>

  </div>
</template>

<script>
import {listOverOneData, listOverUser} from "@/api/app/data/data";

export default {
  name: "CapitalBack",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 用户表格数据
      indexList: null,
      list: null,
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 日期范围
      dateRange: [],
      userList: [],
      // 表单参数
      form: {},
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userId: undefined,
        beginTime: undefined,
        endTime: undefined
      },
    };
  },
  watch: {},
  created() {
    this.getList();
    this.getListOneOverUser();
  },
  methods: {
    /** 查询列表 */
    getList() {
      this.loading = true;
      if (this.dateRange) {
        this.queryParams.beginTime = this.dateRange[0];
        this.queryParams.endTime = this.dateRange[1];
      } else {
        this.queryParams.beginTime = undefined;
        this.queryParams.endTime = undefined;
      }
      listOverOneData(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
          this.indexList = response.rows;
          this.total = response.total;
          this.loading = false;
        }
      );
    },

    getListOneOverUser() {
      listOverUser({type: '1'}).then(response => {
          this.userList = response.data;
        }
      );
    },


    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },

    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        applyMoney: 0,
        manageMoney: 0,
        examineMoney: 0,
        serviceMoney: 0,
        cycle: 0,
        realMoney: 0,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
      // this.getTotalList();
    },


    handleMoney() {
      this.form.realMoney = this.form.applyMoney - this.form.manageMoney - this.form.examineMoney - this.form.serviceMoney;
    },

    /** 导出按钮操作 */
    handleExport() {
      this.download('/system/app/data/overOneData/export', {
        ...this.queryParams
      }, `s0监督数据_${new Date().getTime()}.xlsx`)
    },
  },
  filters: {
    numFilter: (value) => {
      return value = parseFloat(value * 100).toFixed(2)
    },
    numFilter1: (value) => {
      return value = parseFloat(value).toFixed(0)
    }
  }
};
</script>
